package com.cv.system.controller.platform.user;

import com.cv.framework.common.pojo.Result;
import com.cv.framework.security.core.utils.SecurityFrameworkUtil;
import com.cv.system.controller.platform.user.vo.PlatformUserPasswordReqVO;
import com.cv.system.controller.platform.user.vo.PlatformUserProfilePasswordReqVO;
import com.cv.system.controller.platform.user.vo.PlatformUserProfileRespVO;
import com.cv.system.controller.platform.user.vo.PlatformUserProfileSaveReqVO;
import com.cv.system.service.user.SystemUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

import static com.cv.framework.common.pojo.Result.success;

/**
 * 视频平台 - 用户信息
 *
 * @author Charles_XDXD
 */
@Tag(name = "视频平台 - 用户信息")
@RestController
@RequestMapping("/system/user")
public class PlatformUserController {

    @Resource
    private SystemUserService systemUserService;

    @GetMapping("profile")
    @PermitAll
    public Result<PlatformUserProfileRespVO> getUserProfile(Long userId) {
        return success(systemUserService.getUserPlatformProfile(userId));
    }

    @PutMapping("modify")
    public Result<Void> modifyUserProfile(@RequestBody PlatformUserProfileSaveReqVO platformUserProfileSaveReqVO) {
        systemUserService.updateUserProfile(platformUserProfileSaveReqVO);
        return success();
    }

    @PutMapping("saveAvatar")
    public Result<Void> saveAvatar(Long avatar) {
        systemUserService.updateAvatar(SecurityFrameworkUtil.getLoginUserId(), avatar);
        return success();
    }

    @PutMapping("modifyPassword")
    @Operation(summary = "修改密码")
    public Result<Void> modifyPassword(@RequestBody PlatformUserProfilePasswordReqVO reqVO) {
        systemUserService.modifyUserPassword(reqVO);
        return success();
    }

    @PutMapping("modifyPasswordByUsername")
    @Operation(summary = "修改密码")
    @PermitAll
    public Result<Void> modifyPasswordByUsername(@RequestBody PlatformUserPasswordReqVO reqVO) {
        systemUserService.modifyUserPassword(reqVO);
        return success();
    }
    
    @PutMapping("modifyEmail")
    @Operation(summary = "修改邮箱")
    public Result<Void> modifyEmail(String email) {
        systemUserService.modifyEmail(email);
        return success();
    }
    
}
